import { useEffect, useState } from "react";
import HomePage_TableComponent from "../../../../component/table";
import { $Http } from "../../../../../../network";
import { $EventBus_off, $EventBus_on, $export_excel } from "../../../../../../common/utils";
import dayjs from 'dayjs';
import HomePage_ModalComponent from "../../../../component/modal";
import HomePage_StatisticalQueryPage_AssessmentReportPage_AddModalComponent from "./component/addModal";
import HomePage_StatisticalQueryPage_AssessmentReportPage_SeeModalComponent from "./component/seeModal";
// 主页-统计查询页面-评估报告页面
const HomePage_StatisticalQueryPage_AssessmentReportPage: React.FC = () => {
    let [pageNo, setPageNo] = useState<number>(1)
    let [pageSize, setPageSize] = useState<number>(10)
    const [sourceData, setSourceData] = useState<object>({ list: [{}] })
    const [modalData, setModalData] = useState<object>({})
    const [isAddModal, setIsAddModal] = useState<boolean>(false)
    const [isSeeModal, setIsSeeModal] = useState<boolean>(false)
    const columnList = [
        {
            title: '序号',
            width: 60,
            render: (text: string, record: object, idx: number) => idx + 1,
        },
        {
            title: '创建时间',
            minWidth: 85,
            dataIndex: 'createTime',
            render: (text: string) => text ?? "-"
        },
        {
            title: '创建账号',
            minWidth: 85,
            dataIndex: 'userName',
            render: (text: string) => text ?? "-"
        },
        {
            title: '站点名称',
            minWidth: 85,
            dataIndex: 'stationName',
            render: (text: string) => text ?? "-"
        },
        {
            title: '报告名称',
            minWidth: 85,
            dataIndex: 'reportName',
            render: (text: string) => text ?? "-"
        },
        {
            title: '操作',
            align: "right",
            width: 100,
            fixed: "right",
            render: (text: string, record: object, idx: number) => <>
                <span className="homePage-tableOperationBtn" onClick={() => click_operation("see", record["data"])}>查看</span>
            </>
        },
    ];
    const http_search = () => {
        $Http("search", { typeName: "统计查询/评估报告", pageNo, pageSize }).then((res) => {
            setSourceData({ ...res["data"] })
        })
    }

    const click_operation = (type: string, data: object) => {
        switch (type) {
            case "see":
                setIsSeeModal(true)
                setModalData({ type, ...data })
                break
        }
    }

    const change_pagination = (no: number, size: number) => {
        pageNo = no
        pageSize = size
        setPageNo(pageNo)
        setPageSize(pageSize)
        http_search()
    }
    const change_export = (list: Array<number>) => {
        $export_excel("统计查询/评估报告", list)
    }
    // 广播函数数据
    const eventBusFuncData = {
        // 头部操作新增
        headerOperationAdd: (data) => {
            setModalData({ type: "add" })
            setIsAddModal(true)
        },

    }
    useEffect(() => {
        http_search()
        $EventBus_on(eventBusFuncData)
        return () => {
            $EventBus_off(eventBusFuncData)
        }
    }, [])
    return (
        <>
            <HomePage_TableComponent name="homePageStatisticalQueryPageAssessmentReportPageTable" isRowSelection alignRightList={["操作"]}
                columnList={columnList} pageNo={pageNo} pageSize={pageSize} sourceData={sourceData} change_pagination={change_pagination} change_selectedRowList={change_export} />
            {
                isAddModal && <HomePage_ModalComponent width={730} change_cancel={setIsAddModal} contentComponent={<HomePage_StatisticalQueryPage_AssessmentReportPage_AddModalComponent change_cancel={setIsAddModal} />} />
            }
            {
                isSeeModal && <HomePage_ModalComponent width={1000} change_cancel={setIsSeeModal} contentComponent={<HomePage_StatisticalQueryPage_AssessmentReportPage_SeeModalComponent sourceData={modalData} change_cancel={setIsSeeModal} />} />
            }
        </>
    )
}

export default HomePage_StatisticalQueryPage_AssessmentReportPage

